package mo.leetcode_top;

import java.util.Arrays;

public class L279 {

    public int numSquares(int n) {
        int[] dp = new int[n+1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 0; i <= n; i++) {
            int x = 0;
            for (int j = 1; (x = j * j + i) <= n; j++) {
                dp[x] = Math.min(dp[x], dp[i]+1);
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        L279 test = new L279();
        System.out.println(test.numSquares(13));
    }

}
